﻿using DevExpress.XtraSplashScreen;
using System;
using System.Drawing;
using System.Threading;

namespace DevExpress.SplashScreen
{
    public partial class FormMain : DevExpress.XtraEditors.XtraForm
    {
        public FormMain()
        {
            InitializeComponent();
        }

        private void OnSkinSplashScreenClick(object sender, EventArgs e)
        {
            var logo = this.sbSkinSplashScreen.ImageOptions.Image;
            SplashScreenManager.ShowSkinSplashScreen(
                logoImage: logo,
                title: "这是Skin Splash Screen标题..",
                subtitle: "这是Skin Splash Screen副标题..",
                footer: "Copyright © 1990 - 2025 Armon Inc." + Environment.NewLine + "All Rights reserved.",
                loading: "加载中..",
                parentForm: this,
                useFadeIn: true,
                useFadeOut: true,
                startPos: SplashFormStartPosition.CenterScreen
            );
            Thread.Sleep(TimeSpan.FromSeconds(5));

            // TODO: 下面可以添加逻辑
            //...

            // 更新
            /* 可更新的内容
            SkinSplashScreenCommand.UpdateTitle
            SkinSplashScreenCommand.UpdateSubtitle
            SkinSplashScreenCommand.UpdateFooter
            SkinSplashScreenCommand.UpdateLoadingText
            SkinSplashScreenCommand.UpdateLogoImage
            SkinSplashScreenCommand.UpdateSvgImageSize
            */
            SplashScreenManager.Default.SendCommand(SkinSplashScreenCommand.UpdateLoadingText, "完成");
            Thread.Sleep(TimeSpan.FromSeconds(1));
            // 关闭
            SplashScreenManager.CloseForm();
        }

        private void OnFluentSplashScreenClick(object sender, EventArgs e)
        {
            var options = new FluentSplashScreenOptions()
            {
                Title = "这是Skin Splash Screen标题..",
                Subtitle = "这是Skin Splash Screen副标题..",
                RightFooter = "加载中...",
                LeftFooter = "Copyright © 1990 - 2025 Armon Inc." + Environment.NewLine + "All Rights reserved.",
                LoadingIndicatorType = FluentLoadingIndicatorType.Dots,
                OpacityColor = Color.Gray,
                Opacity = 130,
            };
            options.LogoImageOptions.SvgImage = this.sbFluentSplashScreen.ImageOptions.SvgImage;

            SplashScreenManager.ShowFluentSplashScreen(
                fluentOptions: options,
                parentForm: this,
                useFadeIn: true,
                useFadeOut: true
            );
            Thread.Sleep(TimeSpan.FromSeconds(5));

            //TODO: 添加逻辑
            //...

            // 更新
            SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, new FluentSplashScreenOptions()
            {
                RightFooter = "完成",
                Title = "哈哈哈哈，终于...",
                Subtitle = "我要这天，再遮不住我眼",
            });
            Thread.Sleep(TimeSpan.FromSeconds(1));
            //关闭
            SplashScreenManager.CloseForm();
        }

        private void OnSplashImageClick(object sender, EventArgs e)
        {
            var image = this.sbSplashImage.ImageOptions.SvgImage;
            SplashScreenManager.ShowImage(image);
            Thread.Sleep(TimeSpan.FromSeconds(2));
            //TODO: 添加逻辑
            //...
            SplashScreenManager.HideImage();
        }

        private void OnWaitFormClick(object sender, EventArgs e)
        {
            this.ssmManager.ShowWaitForm();
            Thread.Sleep(TimeSpan.FromSeconds(2));
            //TODO: 添加逻辑
            //...
            //...
            this.ssmManager.CloseWaitForm();
        }

        private void OnOverlayFormClick(object sender, EventArgs e)
        {
            var options = new OverlayWindowOptions(
                startupDelay: 1000,
                backColor: Color.Green,
                opacity: 0.8,
                fadeIn: true,
                fadeOut: true,
                imageSize: new Size(64, 64)
            );

            using (var handle = SplashScreenManager.ShowOverlayForm(this, options))
            {
                handle.QueueFocus(IntPtr.Zero);
                Thread.Sleep(TimeSpan.FromSeconds(5));

                //TODO: 添加逻辑
                //...
                //...
            }
        }
    }
}
